from tools.my_methods import *


class Solution:
    def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:
        mm = {}
        for i in range(len(arr2)):
            mm[arr2[i]] = i
        data = []
        data2 = []
        for i in range(len(arr1)):
            if mm.get(arr1[i]) is not None:
                data.append((arr1[i], mm[arr1[i]]))
            else:
                data2.append(arr1[i])
        data.sort(key=lambda x: x[1])
        data2.sort()
        ans = list(map(lambda x: x[0], data))
        ans.extend(data2)
        return ans


questions = [
    ([2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], [2, 1, 4, 3, 9, 6]),
]

work(questions, lambda q: Solution().relativeSortArray(q[0], q[1]))
